<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Geocoder/Map24Geocoder.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


// definition of the coordinates to reverse-geocode

// first coordinate
$coorIdx=0;
$coordinates[$coorIdx]['longitude']= "514.048";
$coordinates[$coorIdx]['latitude'] = "3007.8325";

// second coordinate
$coorIdx++;
$coordinates[$coorIdx]['longitude']= "500.032";
$coordinates[$coorIdx]['latitude'] = "3000.0825";
// third coordinate
$coorIdx++;
$coordinates[$coorIdx]['longitude']= "799.095";
$coordinates[$coorIdx]['latitude'] = "3150.81";
// fourth coordinate
$coorIdx++;
$coordinates[$coorIdx]['longitude']= "417.147";
$coordinates[$coorIdx]['latitude'] = "3056.051";


// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new ReverseGeocodeAddressesRequest();
$request->Coordinates = array();

for($coorIdx=0;$coorIdx<count($coordinates);$coorIdx++)
{
	$request->Coordinates[$coorIdx] = new Coordinate();
	$request->Coordinates[$coorIdx]->Longitude = $coordinates[$coorIdx]['longitude'];
	$request->Coordinates[$coorIdx]->Latitude = $coordinates[$coorIdx]['latitude'];
}


// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$geocoder = new Map24Geocoder($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
$response = $geocoder->reverseGeocodeAddresses($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


if(isset($response->GeocodedAddresses) && count($response->GeocodedAddresses) > 0)
{
	for($i=0;$i<count($response->GeocodedAddresses);$i++)
	{
		$counter++;
		$resultString .= "<div><b>".$counter.".</b><br/>";
		$resultString.= "Street: ".$response->GeocodedAddresses[$i]->Alternatives[0]->Street."<br/>";
		$resultString.= "HouseNo: ".$response->GeocodedAddresses[$i]->Alternatives[0]->HouseNo."<br/>";
		$resultString.= "ZIP, City: ".$response->GeocodedAddresses[$i]->Alternatives[0]->ZIP." ".$response->GeocodedAddresses[$i]->Alternatives[0]->City."<br/>";
		$resultString.= "Country: ".$response->GeocodedAddresses[$i]->Alternatives[0]->Country."<br/><br/>";
		$resultString .= "</div>";
	}
}
else
{
	$resultString = "Sorry, no results found";
}

?>